%     VIRTUAL FABRIC - программа для получения эффективных свойств текстильных композитов
%     Copyright (C) 2020  Михаил Козлов
%     Сайт проекта: <http://www.fastenerdoctor.ru/>
%     Адрес электронной почты для связи с разработчиком:
%     <doctor.fastener@gmail.com>
% 
%     Эта программа является свободным программным обеспечением: Вы можете
%     распространять ее и/или изменять, соблюдая условия Универсальной общественной
%     лицензии GNU, опубликованной Фондом свободного программного обеспечения,
%     либо редакции 3, либо (на Ваше усмотрение) любой редакции, выпущенной позже.
% 
%     Эта программа распространяется в надежде на то, что она окажется полезной,
%     но БЕЗ КАКИХ-ЛИБО ГАРАНТИЙ, включая даже подразумеваемую гарантию ТОВАРНОЙ ПРИГОДНОСТИ,
%     либо ПРИГОДНОСТИ ДЛЯ ОПРЕДЕЛЕННЫХ ЦЕЛЕЙ. Ознакомьтесь с Универсальной общественной
%     лицензией GNU для получения более подробной информации.
% 
%     Вы должны были получить копию Универсальной общественной лицензии GNU
%     вместе с этой программой. Если Вы ее не получили, то перейдите по адресу:
%     <http://www.gnu.org/licenses/>.
% 
%     This program is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     (at your option) any later version.
% 
%     This program is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%     GNU General Public License for more details.
% 
%     You should have received a copy of the GNU General Public License
%     along with this program.  If not, see <https://www.gnu.org/licenses/>.

function Write_BC_Thermal(Fout, NODES, RVE_Coordinates, Node_Merge_Tolerance, Part_Name, Solver_Parameters)

global ErrCode;

% Формат числовых данных в файле
equation_format = '%.12e';
bc_format = '%.12e';

fprintf (Fout, '**\n');
fprintf (Fout, '** ASSEMBLY\n');
fprintf (Fout, '**\n');

fprintf (Fout, '*Assembly, name=Assembly\n');
fprintf (Fout, '**\n');
fprintf (Fout, '*Instance, name=%s-1, part=%s\n', Part_Name, Part_Name);
fprintf (Fout, '*End Instance\n');
fprintf (Fout, '**\n');

fprintf (Fout, '*Node\n');
fprintf (Fout, '      1,           0.,           0.,           0.\n');
fprintf (Fout, '      2,           0.,           0.,           0.\n');
fprintf (Fout, '      3,           0.,           0.,           0.\n');

fprintf (Fout, '*Nset, nset=RP-ThermGrad_x\n');
fprintf (Fout, ' 1,\n');

fprintf (Fout, '*Nset, nset=RP-ThermGrad_y\n');
fprintf (Fout, ' 2,\n');

fprintf (Fout, '*Nset, nset=RP-ThermGrad_z\n');
fprintf (Fout, ' 3,\n');

RVE_AG_NegX_RVE_AGSORT = Generate_Nset(NODES, RVE_Coordinates(1,1)-Node_Merge_Tolerance, RVE_Coordinates(1,1)+Node_Merge_Tolerance, RVE_Coordinates(2,1)-Node_Merge_Tolerance, RVE_Coordinates(2,2)+Node_Merge_Tolerance, RVE_Coordinates(3,1)-Node_Merge_Tolerance, RVE_Coordinates(3,2)+Node_Merge_Tolerance);
RVE_AG_PosX_RVE_AGSORT = Generate_Nset(NODES, RVE_Coordinates(1,2)-Node_Merge_Tolerance, RVE_Coordinates(1,2)+Node_Merge_Tolerance, RVE_Coordinates(2,1)-Node_Merge_Tolerance, RVE_Coordinates(2,2)+Node_Merge_Tolerance, RVE_Coordinates(3,1)-Node_Merge_Tolerance, RVE_Coordinates(3,2)+Node_Merge_Tolerance);

RVE_AG_NegY_RVE_AGSORT = Generate_Nset(NODES, RVE_Coordinates(1,1)-Node_Merge_Tolerance, RVE_Coordinates(1,2)-Node_Merge_Tolerance, RVE_Coordinates(2,1)-Node_Merge_Tolerance, RVE_Coordinates(2,1)+Node_Merge_Tolerance, RVE_Coordinates(3,1)-Node_Merge_Tolerance, RVE_Coordinates(3,2)+Node_Merge_Tolerance);
RVE_AG_PosY_RVE_AGSORT = Generate_Nset(NODES, RVE_Coordinates(1,1)-Node_Merge_Tolerance, RVE_Coordinates(1,2)-Node_Merge_Tolerance, RVE_Coordinates(2,2)-Node_Merge_Tolerance, RVE_Coordinates(2,2)+Node_Merge_Tolerance, RVE_Coordinates(3,1)-Node_Merge_Tolerance, RVE_Coordinates(3,2)+Node_Merge_Tolerance);

RVE_AG_NegZ_RVE_AGSORT = Generate_Nset(NODES, RVE_Coordinates(1,1)-Node_Merge_Tolerance, RVE_Coordinates(1,2)-Node_Merge_Tolerance, RVE_Coordinates(2,1)-Node_Merge_Tolerance, RVE_Coordinates(2,2)-Node_Merge_Tolerance, RVE_Coordinates(3,1)-Node_Merge_Tolerance, RVE_Coordinates(3,1)+Node_Merge_Tolerance);
RVE_AG_PosZ_RVE_AGSORT = Generate_Nset(NODES, RVE_Coordinates(1,1)-Node_Merge_Tolerance, RVE_Coordinates(1,2)-Node_Merge_Tolerance, RVE_Coordinates(2,1)-Node_Merge_Tolerance, RVE_Coordinates(2,2)-Node_Merge_Tolerance, RVE_Coordinates(3,2)-Node_Merge_Tolerance, RVE_Coordinates(3,2)+Node_Merge_Tolerance);

if (isempty(RVE_AG_NegX_RVE_AGSORT))
    fprintf (1, '\nОшибка: не удалось найти узлы для сэта RVE_AG_NegX_RVE_AGSORT !\n');
    fprintf (1, 'Измените параметры построения сетки.\n');
    fclose(Fout);
    ErrCode = -1;
    return;
end

if (isempty(RVE_AG_NegY_RVE_AGSORT))
    fprintf (1, '\nОшибка: не удалось найти узлы для сэта RVE_AG_NegY_RVE_AGSORT !\n');
    fprintf (1, 'Измените параметры построения сетки.\n');
    fclose(Fout);
    ErrCode = -1;
    return;
end

if (isempty(RVE_AG_NegZ_RVE_AGSORT))
    fprintf (1, '\nОшибка: не удалось найти узлы для сэта RVE_AG_NegZ_RVE_AGSORT !\n');
    fprintf (1, 'Измените параметры построения сетки.\n');
    fclose(Fout);
    ErrCode = -1;
    return;
end

if (isempty(RVE_AG_PosX_RVE_AGSORT))
    fprintf (1, '\nОшибка: не удалось найти узлы для сэта RVE_AG_PosX_RVE_AGSORT !\n');
    fprintf (1, 'Измените параметры построения сетки.\n');
    fclose(Fout);
    ErrCode = -1;
    return;
end

if (isempty(RVE_AG_PosY_RVE_AGSORT))
    fprintf (1, '\nОшибка: не удалось найти узлы для сэта RVE_AG_PosY_RVE_AGSORT !\n');
    fprintf (1, 'Измените параметры построения сетки.\n');
    fclose(Fout);
    ErrCode = -1;
    return;
end

if (isempty(RVE_AG_PosZ_RVE_AGSORT))
    fprintf (1, '\nОшибка: не удалось найти узлы для сэта RVE_AG_PosZ_RVE_AGSORT !\n');
    fprintf (1, 'Измените параметры построения сетки.\n');
    fclose(Fout);
    ErrCode = -1;
    return;
end

if (numel(RVE_AG_NegX_RVE_AGSORT) ~= numel(RVE_AG_PosX_RVE_AGSORT))
    fprintf (1, '\nОшибка: размер сэта RVE_AG_NegX_RVE_AGSORT не совпадает с размером сэта RVE_AG_PosX_RVE_AGSORT !\n');
    fclose(Fout);
    ErrCode = -1;
    return;
end

if (numel(RVE_AG_NegY_RVE_AGSORT) ~= numel(RVE_AG_PosY_RVE_AGSORT))
    fprintf (1, '\nОшибка: размер сэта RVE_AG_NegY_RVE_AGSORT не совпадает с размером сэта RVE_AG_PosY_RVE_AGSORT !\n');
    fclose(Fout);
    ErrCode = -1;
    return;
end

if (numel(RVE_AG_NegZ_RVE_AGSORT) ~= numel(RVE_AG_PosZ_RVE_AGSORT))
    fprintf (1, '\nОшибка: размер сэта RVE_AG_NegZ_RVE_AGSORT не совпадает с размером сэта RVE_AG_PosZ_RVE_AGSORT !\n');
    fclose(Fout);
    ErrCode = -1;
    return;
end

RVE_AG_PosX_RVE_AGSORT = Match_Nodes(RVE_AG_PosX_RVE_AGSORT, RVE_AG_NegX_RVE_AGSORT, NODES, 1, Node_Merge_Tolerance);

if (ErrCode < 0)
    fclose(Fout);
    return;
end

RVE_AG_PosY_RVE_AGSORT = Match_Nodes(RVE_AG_PosY_RVE_AGSORT, RVE_AG_NegY_RVE_AGSORT, NODES, 2, Node_Merge_Tolerance);

if (ErrCode < 0)
    fclose(Fout);
    return;
end

RVE_AG_PosZ_RVE_AGSORT = Match_Nodes(RVE_AG_PosZ_RVE_AGSORT, RVE_AG_NegZ_RVE_AGSORT, NODES, 3, Node_Merge_Tolerance);

if (ErrCode < 0)
    fclose(Fout);
    return;
end

fprintf (Fout, '*NSET, NSET=RVE_AG_NegX_RVE_AGSORT, UNSORTED, instance=%s-1\n', Part_Name);
Write_Set(Fout, RVE_AG_NegX_RVE_AGSORT);

fprintf (Fout, '*NSET, NSET=RVE_AG_PosX_RVE_AGSORT, UNSORTED, instance=%s-1\n', Part_Name);
Write_Set(Fout, RVE_AG_PosX_RVE_AGSORT);

fprintf (Fout, '*NSET, NSET=RVE_AG_NegY_RVE_AGSORT, UNSORTED, instance=%s-1\n', Part_Name);
Write_Set(Fout, RVE_AG_NegY_RVE_AGSORT);

fprintf (Fout, '*NSET, NSET=RVE_AG_PosY_RVE_AGSORT, UNSORTED, instance=%s-1\n', Part_Name);
Write_Set(Fout, RVE_AG_PosY_RVE_AGSORT);

fprintf (Fout, '*NSET, NSET=RVE_AG_NegZ_RVE_AGSORT, UNSORTED, instance=%s-1\n', Part_Name);
Write_Set(Fout, RVE_AG_NegZ_RVE_AGSORT);

fprintf (Fout, '*NSET, NSET=RVE_AG_PosZ_RVE_AGSORT, UNSORTED, instance=%s-1\n', Part_Name);
Write_Set(Fout, RVE_AG_PosZ_RVE_AGSORT);

fprintf (Fout, '**\n');
fprintf (Fout, '** EQUATIONS\n');
fprintf (Fout, '**\n');

fprintf (Fout, '*Equation\n');

fprintf (Fout, '3\n');
fprintf (Fout, ['RVE_AG_PosX_RVE_AGSORT, 11, -1.000000e+00, RVE_AG_NegX_RVE_AGSORT, 11, 1.000000e+00, RP-ThermGrad_x, 11, ' equation_format '\n'], RVE_Coordinates(1,2) - RVE_Coordinates(1,1));
fprintf (Fout, '3\n');
fprintf (Fout, ['RVE_AG_PosY_RVE_AGSORT, 11, -1.000000e+00, RVE_AG_NegY_RVE_AGSORT, 11, 1.000000e+00, RP-ThermGrad_y, 11, ' equation_format '\n'], RVE_Coordinates(2,2) - RVE_Coordinates(2,1));
fprintf (Fout, '3\n');
fprintf (Fout, ['RVE_AG_PosZ_RVE_AGSORT, 11, -1.000000e+00, RVE_AG_NegZ_RVE_AGSORT, 11, 1.000000e+00, RP-ThermGrad_z, 11, ' equation_format '\n'], RVE_Coordinates(3,2) - RVE_Coordinates(3,1));

fprintf (Fout, '*End Assembly\n');

fprintf (Fout, '** ----------------------------------------------------------------\n');

fprintf (Fout, '**\n');
fprintf (Fout, '** STEP: HomogK_X-Initial\n');
fprintf (Fout, '**\n');

switch Solver_Parameters.Heat_Transfer_Solver
    case 'DIRECT'
        fprintf (Fout, '*Step, name=HomogK_X-Initial, nlgeom=NO\n');
        fprintf (Fout, 'RP_grad\n');
        fprintf (Fout, '*Heat Transfer, steady state, deltmx=0.\n');
        fprintf (Fout, '1e-08, 1e-08, 1e-13, 1e-08, \n');
    case 'ITERATIVE'
        fprintf (Fout, '*Step, name=HomogK_X-Initial, nlgeom=NO, solver=ITERATIVE, unsymm=NO\n');
        fprintf (Fout, 'RP_grad\n');
        fprintf (Fout, '*Heat Transfer, steady state, deltmx=0.\n');
        fprintf (Fout, '1e-08, 1e-08, 1e-13, 1e-08, \n');
        fprintf (Fout, '**\n');
        fprintf (Fout, '** SOLVER CONTROLS\n');
        fprintf (Fout, '**\n');
        fprintf (Fout, '*Solver Controls, reset\n');
        fprintf (Fout, '*Solver Controls\n');
        fprintf (Fout, '%e, %i\n', Solver_Parameters.Heat_Transfer_Rel_Tol, Solver_Parameters.Heat_Transfer_Max_Iter);
end

fprintf (Fout, '**\n');
fprintf (Fout, '** BOUNDARY CONDITIONS\n');
fprintf (Fout, '**\n');

fprintf (Fout, '** Name: HomogK_X-Initial-dTX Type: Temperature\n');
fprintf (Fout, '*Boundary\n');
fprintf (Fout, ['RP-ThermGrad_x, 11, 11, ' bc_format '\n'], 1/(RVE_Coordinates(1,2) - RVE_Coordinates(1,1)));

fprintf (Fout, '** Name: HomogK_X-Initial-dTY Type: Temperature\n');
fprintf (Fout, '*Boundary\n');
fprintf (Fout, 'RP-ThermGrad_y, 11, 11\n');

fprintf (Fout, '** Name: HomogK_X-Initial-dTZ Type: Temperature\n');
fprintf (Fout, '*Boundary\n');
fprintf (Fout, 'RP-ThermGrad_z, 11, 11\n');

fprintf (Fout, '**\n');
fprintf (Fout, '** OUTPUT REQUESTS\n');
fprintf (Fout, '**\n');

fprintf (Fout, '*Restart, write, frequency=0\n');

fprintf (Fout, '**\n');
fprintf (Fout, '** FIELD OUTPUT: ThermalFieldOutput\n');
fprintf (Fout, '**\n');

fprintf (Fout, '*Output, field\n');
fprintf (Fout, '*Node Output\n');
fprintf (Fout, 'NT, RFL\n');

fprintf (Fout, '*Element Output, directions=YES\n');
fprintf (Fout, 'FLUXS, HFL, IVOL, TEMP\n');

fprintf (Fout, '**\n');
fprintf (Fout, '** FIELD OUTPUT: F-Output-1\n');
fprintf (Fout, '**\n');

fprintf (Fout, '*Output, field, variable=PRESELECT\n');

fprintf (Fout, '**\n');
fprintf (Fout, '** HISTORY OUTPUT: RP-ThermGrad_x_History\n');
fprintf (Fout, '**\n');

fprintf (Fout, '*Output, history\n');
fprintf (Fout, '*Node Output, nset=RP-ThermGrad_x\n');
fprintf (Fout, 'CFL, NT, RFL\n');

fprintf (Fout, '**\n');
fprintf (Fout, '** HISTORY OUTPUT: RP-ThermGrad_y_History\n');
fprintf (Fout, '**\n');

fprintf (Fout, '*Node Output, nset=RP-ThermGrad_y\n');
fprintf (Fout, 'CFL, NT, RFL\n');

fprintf (Fout, '**\n');
fprintf (Fout, '** HISTORY OUTPUT: RP-ThermGrad_z_History\n');
fprintf (Fout, '**\n');

fprintf (Fout, '*Node Output, nset=RP-ThermGrad_z\n');
fprintf (Fout, 'CFL, NT, RFL\n');

fprintf (Fout, '*EL PRINT, ELSET=%s-1.ALL_ELEMENTS, POSITION=INTEGRATION POINTS, FREQUENCY=99999\n', Part_Name);
fprintf (Fout, 'HFL, IVOL\n');

fprintf (Fout, '*End Step\n');

fprintf (Fout, '** ----------------------------------------------------------------\n');

fprintf (Fout, '**\n');
fprintf (Fout, '** STEP: HomogK_Y-Initial\n');
fprintf (Fout, '**\n');

switch Solver_Parameters.Heat_Transfer_Solver
    case 'DIRECT'
        fprintf (Fout, '*Step, name=HomogK_Y-Initial, nlgeom=NO\n');
        fprintf (Fout, 'RP_grad\n');
        fprintf (Fout, '*Heat Transfer, steady state, deltmx=0.\n');
        fprintf (Fout, '1e-08, 1e-08, 1e-13, 1e-08, \n');
    case 'ITERATIVE'
        fprintf (Fout, '*Step, name=HomogK_Y-Initial, nlgeom=NO, solver=ITERATIVE, unsymm=NO\n');
        fprintf (Fout, 'RP_grad\n');
        fprintf (Fout, '*Heat Transfer, steady state, deltmx=0.\n');
        fprintf (Fout, '1e-08, 1e-08, 1e-13, 1e-08, \n');
        fprintf (Fout, '**\n');
        fprintf (Fout, '** SOLVER CONTROLS\n');
        fprintf (Fout, '**\n');
        fprintf (Fout, '*Solver Controls, reset\n');
        fprintf (Fout, '*Solver Controls\n');
        fprintf (Fout, '%e, %i\n', Solver_Parameters.Heat_Transfer_Rel_Tol, Solver_Parameters.Heat_Transfer_Max_Iter);
end

fprintf (Fout, '**\n');
fprintf (Fout, '** BOUNDARY CONDITIONS\n');
fprintf (Fout, '**\n');

fprintf (Fout, '** Name: HomogK_X-Initial-dTX Type: Temperature\n');
fprintf (Fout, '*Boundary, op=NEW\n');

fprintf (Fout, '** Name: HomogK_X-Initial-dTY Type: Temperature\n');
fprintf (Fout, '*Boundary, op=NEW\n');

fprintf (Fout, '** Name: HomogK_X-Initial-dTZ Type: Temperature\n');
fprintf (Fout, '*Boundary, op=NEW\n');

fprintf (Fout, '** Name: HomogK_Y-Initial-dTX Type: Temperature\n');
fprintf (Fout, '*Boundary, op=NEW\n');
fprintf (Fout, 'RP-ThermGrad_x, 11, 11\n');

fprintf (Fout, '** Name: HomogK_Y-Initial-dTY Type: Temperature\n');
fprintf (Fout, '*Boundary, op=NEW\n');
fprintf (Fout, ['RP-ThermGrad_y, 11, 11, ' bc_format '\n'], 1/(RVE_Coordinates(2,2) - RVE_Coordinates(2,1)));

fprintf (Fout, '** Name: HomogK_Y-Initial-dTZ Type: Temperature\n');
fprintf (Fout, '*Boundary, op=NEW\n');
fprintf (Fout, 'RP-ThermGrad_z, 11, 11\n');

fprintf (Fout, '**\n');
fprintf (Fout, '** OUTPUT REQUESTS\n');
fprintf (Fout, '**\n');

fprintf (Fout, '*Restart, write, frequency=0\n');

fprintf (Fout, '**\n');
fprintf (Fout, '** FIELD OUTPUT: ThermalFieldOutput\n');
fprintf (Fout, '**\n');

fprintf (Fout, '*Output, field\n');
fprintf (Fout, '*Node Output\n');
fprintf (Fout, 'NT, RFL\n');

fprintf (Fout, '*Element Output, directions=YES\n');
fprintf (Fout, 'FLUXS, HFL, IVOL, TEMP\n');

fprintf (Fout, '**\n');
fprintf (Fout, '** FIELD OUTPUT: F-Output-1\n');
fprintf (Fout, '**\n');

fprintf (Fout, '*Output, field, variable=PRESELECT\n');

fprintf (Fout, '**\n');
fprintf (Fout, '** HISTORY OUTPUT: RP-ThermGrad_x_History\n');
fprintf (Fout, '**\n');

fprintf (Fout, '*Output, history\n');
fprintf (Fout, '*Node Output, nset=RP-ThermGrad_x\n');
fprintf (Fout, 'CFL, NT, RFL\n');

fprintf (Fout, '**\n');
fprintf (Fout, '** HISTORY OUTPUT: RP-ThermGrad_y_History\n');
fprintf (Fout, '**\n');

fprintf (Fout, '*Node Output, nset=RP-ThermGrad_y\n');
fprintf (Fout, 'CFL, NT, RFL\n');

fprintf (Fout, '**\n');
fprintf (Fout, '** HISTORY OUTPUT: RP-ThermGrad_z_History\n');
fprintf (Fout, '**\n');

fprintf (Fout, '*Node Output, nset=RP-ThermGrad_z\n');
fprintf (Fout, 'CFL, NT, RFL\n');

fprintf (Fout, '*EL PRINT, ELSET=%s-1.ALL_ELEMENTS, POSITION=INTEGRATION POINTS, FREQUENCY=99999\n', Part_Name);
fprintf (Fout, 'HFL, IVOL\n');

fprintf (Fout, '*End Step\n');

fprintf (Fout, '** ----------------------------------------------------------------\n');

fprintf (Fout, '**\n');
fprintf (Fout, '** STEP: HomogK_Z-Initial\n');
fprintf (Fout, '**\n');

switch Solver_Parameters.Heat_Transfer_Solver
    case 'DIRECT'
        fprintf (Fout, '*Step, name=HomogK_Z-Initial, nlgeom=NO\n');
        fprintf (Fout, 'RP_grad\n');
        fprintf (Fout, '*Heat Transfer, steady state, deltmx=0.\n');
        fprintf (Fout, '1e-08, 1e-08, 1e-13, 1e-08, \n');
    case 'ITERATIVE'
        fprintf (Fout, '*Step, name=HomogK_Z-Initial, nlgeom=NO, solver=ITERATIVE, unsymm=NO\n');
        fprintf (Fout, 'RP_grad\n');
        fprintf (Fout, '*Heat Transfer, steady state, deltmx=0.\n');
        fprintf (Fout, '1e-08, 1e-08, 1e-13, 1e-08, \n');
        fprintf (Fout, '**\n');
        fprintf (Fout, '** SOLVER CONTROLS\n');
        fprintf (Fout, '**\n');
        fprintf (Fout, '*Solver Controls, reset\n');
        fprintf (Fout, '*Solver Controls\n');
        fprintf (Fout, '%e, %i\n', Solver_Parameters.Heat_Transfer_Rel_Tol, Solver_Parameters.Heat_Transfer_Max_Iter);
end

fprintf (Fout, '**\n');
fprintf (Fout, '** BOUNDARY CONDITIONS\n');
fprintf (Fout, '**\n');

fprintf (Fout, '** Name: HomogK_Y-Initial-dTX Type: Temperature\n');
fprintf (Fout, '*Boundary, op=NEW\n');

fprintf (Fout, '** Name: HomogK_Y-Initial-dTY Type: Temperature\n');
fprintf (Fout, '*Boundary, op=NEW\n');

fprintf (Fout, '** Name: HomogK_Y-Initial-dTZ Type: Temperature\n');
fprintf (Fout, '*Boundary, op=NEW\n');

fprintf (Fout, '** Name: HomogK_Z-Initial-dTX Type: Temperature\n');
fprintf (Fout, '*Boundary, op=NEW\n');
fprintf (Fout, 'RP-ThermGrad_x, 11, 11\n');

fprintf (Fout, '** Name: HomogK_Z-Initial-dTY Type: Temperature\n');
fprintf (Fout, '*Boundary, op=NEW\n');
fprintf (Fout, 'RP-ThermGrad_y, 11, 11\n');

fprintf (Fout, '** Name: HomogK_Z-Initial-dTZ Type: Temperature\n');
fprintf (Fout, '*Boundary, op=NEW\n');
fprintf (Fout, ['RP-ThermGrad_z, 11, 11, ' bc_format '\n'], 1/(RVE_Coordinates(3,2) - RVE_Coordinates(3,1)));

fprintf (Fout, '**\n');
fprintf (Fout, '** OUTPUT REQUESTS\n');
fprintf (Fout, '**\n');

fprintf (Fout, '*Restart, write, frequency=0\n');

fprintf (Fout, '**\n');
fprintf (Fout, '** FIELD OUTPUT: ThermalFieldOutput\n');
fprintf (Fout, '**\n');

fprintf (Fout, '*Output, field\n');
fprintf (Fout, '*Node Output\n');
fprintf (Fout, 'NT, RFL\n');

fprintf (Fout, '*Element Output, directions=YES\n');
fprintf (Fout, 'FLUXS, HFL, IVOL, TEMP\n');

fprintf (Fout, '**\n');
fprintf (Fout, '** FIELD OUTPUT: F-Output-1\n');
fprintf (Fout, '**\n');

fprintf (Fout, '*Output, field, variable=PRESELECT\n');

fprintf (Fout, '**\n');
fprintf (Fout, '** HISTORY OUTPUT: RP-ThermGrad_x_History\n');
fprintf (Fout, '**\n');

fprintf (Fout, '*Output, history\n');
fprintf (Fout, '*Node Output, nset=RP-ThermGrad_x\n');
fprintf (Fout, 'CFL, NT, RFL\n');

fprintf (Fout, '**\n');
fprintf (Fout, '** HISTORY OUTPUT: RP-ThermGrad_y_History\n');
fprintf (Fout, '**\n');

fprintf (Fout, '*Node Output, nset=RP-ThermGrad_y\n');
fprintf (Fout, 'CFL, NT, RFL\n');

fprintf (Fout, '**\n');
fprintf (Fout, '** HISTORY OUTPUT: RP-ThermGrad_z_History\n');
fprintf (Fout, '**\n');

fprintf (Fout, '*Node Output, nset=RP-ThermGrad_z\n');
fprintf (Fout, 'CFL, NT, RFL\n');

fprintf (Fout, '*EL PRINT, ELSET=%s-1.ALL_ELEMENTS, POSITION=INTEGRATION POINTS, FREQUENCY=99999\n', Part_Name);
fprintf (Fout, 'HFL, IVOL\n');

fprintf (Fout, '*End Step\n');
